<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程指引列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" name="lessonId" id="lessonId" th:value="${lesson.id}"/>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add(1)" shiro:hasPermission="lesson:lessonguide:add">
                    <i class="fa fa-plus"></i> 添加图片
                </a>
                <a class="btn btn-primary" onclick="add(2)" shiro:hasPermission="lesson:lessonguide:add">
                    <i class="fa fa-edit"></i> 添加富文本
                </a>
                <a class="btn btn-danger" onclick="preview()" shiro:hasPermission="lesson:lessonguide:view">
                    <i class="fa fa-remove"></i> 预览
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('lesson:lessonguide:edit')}]];
        var removeFlag = [[${@permission.hasPermi('lesson:lessonguide:remove')}]];
        var typeDatas = [[${@dict.getType('lesson_poster_category')}]];
        var prefix = ctx + "lesson/lessonguide";

        $(function() {
            var options = {
                sortName: "sort",
     		    sortOrder: "asc",
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "课程指引",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'imgUri', 
                    title : '图片地址',
                    formatter: function(value, row, index) {
                       if(row.type == 1){
                           return `<img src='${value}' width=120 height=272 />`
                       }else{
                           return `<div style="width:120px;height:12px;">请打看编辑器查看</div>`;
                       }
                    }
                },
                {
                    field : 'type', 
                    title : '类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field : 'sort',
                    title : '排序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function add(type) {
            let title = type == 1?"添加图片": "添加富文本";
		    var lessonId = $("#lessonId").val();
		    let url = `/lesson/lessonguide/add/${lessonId}/${type}`;
		    $.modal.openFull(title, url);
		}

		function preview(){
		   var lessonId = $("#lessonId").val();
		   let url = `/lesson/lessonguide/preview/${lessonId}`
		   $.modal.openFull("指引预览", url);
		}

    </script>
</body>
</html>